//package com.xingkeduo.delayQueue.service;
//
//import com.alibaba.fastjson.JSON;
//import com.rabbitmq.client.Channel;
//import com.xingkeduo.delayQueue.model.TaskModel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.AmqpException;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.core.MessagePostProcessor;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.messaging.handler.annotation.Payload;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.nio.charset.StandardCharsets;
//import java.util.UUID;
//
///**
// * @author chi  2019-02-22 15:41
// **/
//
//@Component
//@Slf4j
//public class RabbitMqTaskService implements TaskService {
//
//    @Resource
//    private RabbitTemplate rabbitTemplate;
//
//
//    public static void main(String[] args) {
//        String a ="34,123,92,34,105,100,92,34,58,92,34,55,53,51,92,34,44,92,34,116,97,115,107,77,111,100,101,108,69,110,117,109,92,34,58,92,34,99,108,111,115,101,95,111,114,100,101,114,92,34,125,34";
//
//        String[] split = a.split(",");
//
//        for (String s : split) {
//            System.out.print((char) Integer.valueOf(s).intValue());
//        }
//
//    }
//
//
//    @Override
//    public void addToDeplayQueue(TaskModel task) {
//        rabbitTemplate.convertAndSend("order.register.delay.exchange", task.getTaskModelEnum().toString(),task, new MessagePostProcessor() {
//            @Override
//            public Message postProcessMessage(Message message) throws AmqpException {
//                message.getMessageProperties().setExpiration(task.getTaskModelEnum().getExpireTime() + "");
//                return message;
//            }
//        }, new CorrelationData(UUID.randomUUID().toString()));
//
//    }
//
//    @Override
//    public boolean removeFromDeplayQueue(TaskModel task) {
//        return false;
//    }
//
//    @RabbitListener(queues = "order.delay.queue")
//    public void transferFromDelayQueue(@Payload String sendMessage, Channel channel, Message message) {
//
//        try {
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (IOException e) {
//            log.error("basicAck 发生异常； ", e);
//        }
//
//        try {
//            String s = new String(message.getBody(), StandardCharsets.UTF_8);
//            log.info("消费者监听交易记录信息:{}", s);
//            TaskModel taskModel = JSON.parseObject(s, TaskModel.class);
//            addToTaskQue(taskModel.getId(), taskModel.getTaskModelEnum().toString());
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            log.error("消息体解析 发生异常； ", e.fillInStackTrace());
//        }
//
//    }
//}
